#{extends 'main.html' /} #{set title:'UserRequests' /}
<head>
<script type="text/javascript">
	$(function(usercurrent) {
		$('#requestsDiv').hide();
		document.getElementById('requestsDiv').innerHTML = "";
	});
</script>
<script type="text/javascript">
	function showRequests(usercurrent) {

		//$('#showRequestsBtn').fadeOut(1000);
		$('#requestsDiv').fadeIn(1000);
		$
				.getJSON(
						'@{UsersController.loadRequests()}',
						{
							'currentUser' : document
									.getElementById("usercurrentHiddenInput").value
						},
						function(data) {
							//alert(data.result);
							if (data != null) {
								//&& data.result == "sizeNotEqualZero") {
								var reqList = {};
								reqList = data.list.split('AAA');
								//alert(reqList[0]);
								var total = "<p><table id=\"beOrgTable\" border=\"1\">";
								for ( var i = 0; i < reqList.length; i = i + 1) {
									var innerList = {};
									innerList = reqList[i].split(',,,');
									//									total += "<p><a href='#' onclick=\"show_orgs('"
									//										+ reqList
									//									+ "')\">"
									//								+ reqList
									//							+ "</a></p>";

									total += "<tr>";

									total += "<td>";
									total += "<label>" + innerList[0]
											+ "</label>"
									//total += "<p> <input type=\"label\" value=\"" + innerList[0] + "\" > </p>"; // can be a href !!
									total += "</td>";

									total += "<td>";
									total += "<label>" + innerList[1]
											+ "</label>"
									//total += "<p> <input type=\"label\" value=\"" + innerList[1] + "\" > </p>";
									total += "</td>";

									total += "<td>";
									total += "<p> <input type=\"button\" id=\"acceptInvitationBtn"
											+ i
											+ "\" value=\" Accept \" onclick=\"replyInvitation("
											+ innerList[2]
											+ ","
											+ true
											+ ")\" > </p>";

									total += "<p> <input type=\"button\" id=\"declineInvitationBtn"
											+ i
											+ "\" value=\" decline \" onclick=\"replyInvitation("
											+ innerList[2]
											+ ","
											+ false
											+ ")\" > </p>";
									total += "</td>";

									total += "</tr>";
								}
								total += "</table>";
								document.getElementById("requestsDiv").innerHTML = total;
							} else {
								alert("No current invitations to be organizer ");
							}

						});
	}
</script>

<script type="application/javascript"> 
	function replyInvitation(invitationID,replyBoolean){
		//$('#showRequestsBtn ').fadeIn(1000);
 		//$('#requestsDiv').fadeOut(1000);
      	alert(replyBoolean);
		$.getJSON('@{UsersController.saveDecisionRequest()}',{'decision':replyBoolean,'requestID':invitationID},function(data){
            	alert(data.result);
    	});
	}
</script>
</head>

<body>
	<div id="content">
		<input type="button" id="showRequestsBtn"
			value=" Requests To Be An Organizer " onclick="showRequests()" />
		<div id="requestsDiv">-</div>
		<input id="usercurrentHiddenInput" type="hidden"
			value="${usercurrent}" />
	</div>

	<div id="sidebar"></div>

</body>
